/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;

import desk.WebClientController;
import ejb.ProductManager;
import hibernate.Product;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
/**
 * Конвертирует обьекты Product
 * @author AGolubinskyy
 */
public class ProductConverter extends AbstractConverter{
    private ProductManager productmanager;
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Application app = context.getApplication();
        clientController = (WebClientController) app.evaluateExpressionGet(context, "#{webClientController}", WebClientController.class);
        productmanager = clientController.getServerManager().getProductManager();
        return productmanager.getProductByID(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return Integer.toString(((Product)value).getId());
    }
}
